from sklearn.datasets import load_iris
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC
from sklearn.model_selection import StratifiedKFold, cross_val_score
import matplotlib.pyplot as plt

X, y = load_iris(return_X_y=True)

models = [('KNN', KNeighborsClassifier()), ('DTC', DecisionTreeClassifier()), ('GNB', GaussianNB()), ('SVM', SVC())]

result_set = []
names = []

for name, model in models:
    skf = StratifiedKFold(n_splits=10)
    cv_score = cross_val_score(model, X, y, cv=skf, scoring='accuracy')
    names.append(name)
    result_set.append(cv_score)
    # 均值，标准差，方差
    print('%s: %.2f  var: %.2f  std: %.2f' % (name, cv_score.mean(), cv_score.var(), cv_score.std()))


plt.boxplot(result_set, labels=names)
plt.show()
